import * as Icon from '@douyinfe/semi-icons'
import { IconSize } from '@douyinfe/semi-ui/lib/es/icons'
import { DetailedHTMLProps } from 'react'

export const iconList = Object.keys(Icon).filter(
  (item) => item !== 'default' && item !== 'convertIcon'
)

interface ICIcon
  extends DetailedHTMLProps<
    React.HTMLAttributes<HTMLSpanElement>,
    HTMLSpanElement
  > {
  icon: string
  size?: IconSize
  spin?: boolean
  rotate?: number
  prefixCls?: string
  type?: string
}

export default function CIcon(props: ICIcon) {
  if (iconList.includes(props.icon)) {
    const ICON = Icon as Record<string, any>
    const Element = ICON[props.icon]
    return <Element {...props} />
  }
  return null
}
